package com.zking.frame;

import com.zking.entity.Address;
import com.zking.utils.Tool工具;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.List;

public class OrderForm extends JDialog {

    public OrderForm(JDialog owner, boolean modal, String name, List<Address> addresses) {
        super(owner, modal);
        this.setBounds(owner.getX() + 15, owner.getY() + 200, 600, 700);
        this.setResizable(false);// 设置窗口不可调整大小
        this.setTitle(name);
        this.setLayout(null);
        JPanel jPanel = new JPanel();
        jPanel.setBounds(0,0,580,690);
        jPanel.setPreferredSize(new Dimension(550,10+150*addresses.size()));
        jPanel.setLayout(null);

        for (int a=0;a<addresses.size();a++){
            JPanel jPanel1 = new JPanel();
            jPanel1.setBounds(0,10+150*a,580,140);
            jPanel1.setLayout(null);
            jPanel1.setBackground(Color.white);
            JLabel jLabel = new JLabel("地址：");
            jLabel.setBounds(10,10,80,60);
            jLabel.setForeground(Color.RED);
            jLabel.setFont(new Font("黑体",Font.BOLD,20));
            jPanel1.add(jLabel);
            JLabel jLabel1 = new JLabel(addresses.get(a).getAddress());
            jLabel1.setBounds(90,10,420,60);
            jLabel1.setFont(new Font("黑体",Font.BOLD,20));
            jPanel1.add(jLabel1);
            JLabel jLabel2 = new JLabel("姓名：");
            jLabel2.setBounds(10,80,80,60);
            jLabel2.setForeground(Color.RED);
            jLabel2.setFont(new Font("黑体",Font.BOLD,20));
            jPanel1.add(jLabel2);
            JLabel jLabel3 = new JLabel(addresses.get(a).getName());
            jLabel3.setBounds(90,80,130,60);
            jLabel3.setFont(new Font("黑体",Font.BOLD,20));
            jPanel1.add(jLabel3);
            JLabel jLabel4 = new JLabel("电话号码：");
            jLabel4.setBounds(220,80,120,60);
            jLabel4.setForeground(Color.RED);
            jLabel4.setFont(new Font("黑体",Font.BOLD,20));
            jPanel1.add(jLabel4);
            JLabel jLabel5 = new JLabel(addresses.get(a).getPhone());
            jLabel5.setBounds(340,80,150,60);
            jLabel5.setFont(new Font("黑体",Font.BOLD,20));
            jPanel1.add(jLabel5);
            String ab = addresses.get(a).getAddress();
            String bc = addresses.get(a).getName();
            String cd = ""+addresses.get(a).getPhone();
            jPanel1.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    if (e.getClickCount()==2){
                        Tool工具 tool工具 = new Tool工具();
                        JPanel jPanel2 = new JPanel();
                        jPanel2.setBounds(0,10,580,140);
                        jPanel2.setLayout(null);
                        jPanel2.setBackground(Color.white);
                        JLabel jLabel = new JLabel("地址：");
                        jLabel.setBounds(10,10,80,60);
                        jLabel.setForeground(Color.RED);
                        jLabel.setFont(new Font("黑体",Font.BOLD,20));
                        jPanel2.add(jLabel);
                        JLabel jLabel11 = new JLabel(ab);
                        jLabel11.setBounds(90,10,420,60);
                        jLabel11.setFont(new Font("黑体",Font.BOLD,20));
                        jPanel2.add(jLabel11);
                        JLabel jLabel2 = new JLabel("姓名：");
                        jLabel2.setBounds(10,80,80,60);
                        jLabel2.setForeground(Color.RED);
                        jLabel2.setFont(new Font("黑体",Font.BOLD,20));
                        jPanel2.add(jLabel2);
                        JLabel jLabel33 = new JLabel(bc);
                        jLabel33.setBounds(90,80,130,60);
                        jLabel33.setFont(new Font("黑体",Font.BOLD,20));
                        jPanel2.add(jLabel33);
                        JLabel jLabel4 = new JLabel("电话号码：");
                        jLabel4.setBounds(220,80,120,60);
                        jLabel4.setForeground(Color.RED);
                        jLabel4.setFont(new Font("黑体",Font.BOLD,20));
                        jPanel2.add(jLabel4);
                        JLabel jLabel55 = new JLabel(cd);
                        jLabel55.setBounds(340,80,150,60);
                        jLabel55.setFont(new Font("黑体",Font.BOLD,20));
                        jPanel2.add(jLabel5);
                        tool工具.setOrderj(jPanel2);
                        dispose();
                    }
                }
            });
            jPanel.add(jPanel1);
        }

        JLabel jLabel = new JLabel("双击实现跟换地址",0);
        jLabel.setBounds(0,0,590,50);
        jLabel.setFont(new Font("黑体",Font.BOLD,20));
        add(jLabel);
        JScrollPane jScrollPane = new JScrollPane(jPanel);
        jScrollPane.setBounds(10,50,560,600);

        add(jScrollPane);
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    }
}
